
# Create your views here.
from django.shortcuts import render
from django.http import HttpResponse
from  myweb.models import Info

# Create your views here.

# 定义视图函数，业务逻辑
def index(request):
    types = request.GET.get('t')
    val = request.GET.get('val')
    if val:
        ob = Info.objects.filter(title__icontains=val)
    else:
        ob = Info.objects.all()
    if types == '0':
        ob = Info.objects.all()
    elif types == "1":  #智联
        ob = Info.objects.filter(source="zhilian")
    elif types == "2":  #猎聘
        ob = Info.objects.filter(source="liepin")
    elif types == "3":  #无忧
        ob = Info.objects.filter(source="wuyou")
    elif types == "4":  #时间
        ob = Info.objects.all().order_by('-release_time')

    # 数据分页
    from django.core.paginator import Paginator
    # 实例化分页类
    paginator = Paginator(ob, 20)
    # 获取当前页码
    p = int(request.GET.get('p', 1))

    # 获取分页数据对象[{id:1},{id:2}]  [{id:3},{id:4}]
    goodslist = paginator.page(p)

    # 分配数据
    info = {"info": goodslist}
    return render(request,'index.html',info)